<!DOCTYPE html>
<html lang='zh-CN'>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>WinA</title>
    <link rel="stylesheet" type="text/css" href="css/api.css" />
    <link rel="stylesheet" type="text/css" href="css/box.css" />
    <script type="text/javascript" src="script/public.js"></script>
    <style>
    	p{
    		color:#999;
    		padding:5px;
    	}
    </style>
		
    </head>
    <body>
    </body>
    <script type='text/javascript'>
  
  		function initAV(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.init(function(ret){
				if(ret.status){
					alert("初始化成");
					
				}
			});
  		}
  		
  		function login(){
  			var netEaseAVChat = api.require('netEaseAVChat');
  			netEaseAVChat.login({
						account : 'test0',
						token : '6e92a88b45dbd277f16ac1d0c40c1309'
					},function(ret,err){
						api.alert( {msg:JSON.stringify( ret )});
						api.alert( {msg:JSON.stringify( err )});
					});
  		}
  		
  		function enableRtc(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.setRtc({
			   enable: true
			},function(ret){
				api.alert( {msg:JSON.stringify( ret )});
			});
  		}
  		
  		function setParams(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.setParams({
				autoCallProximity : true,
				defaultFrontCamera : true,
				videoQuality : 480
			});
  		}
  		
  		function addLocalView(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.setLocalVideoRender({

			   fixedOn: api.frameName,
			   fixed: true
			});
  		}
  		
  		function setVideo(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.setVideo({
				enable : true
			});
  		}
  		
  		function setPreview(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.setPreview({
				enable : true
			});
  		}
  		
  		function startLocalVideoRender(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.startLocalVideoRender({
			   zFront: true
			});
  		}
  		
  		function call(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.call({
				account : 'test1',
				type : 'video'
			},function(ret,err){
				if(ret.status){
					netEaseAVChat.calleeAckListener({
						enable : true
					},function(ret,err){
						//api.alert( {msg:JSON.stringify( ret )});
						if(ret.status && ret.event == 'agree'){
							api.alert( {msg:'agree'});
							setRemoteView();
							startRemote();
						}else{
							//api.alert( {msg:JSON.stringify( ret )});
						}
					});
					
				}
				//api.alert( {msg:JSON.stringify( ret )});
				//api.alert( {msg:JSON.stringify( err )});
			});
  		}
  		
  		function setRemoteView(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.setRemoteVideoRender({
				rect : {
					h : api.frameHeight - 200
				},
			   fixedOn: api.frameName,
			   fixed: true
			});
  		}
  		
  		function startRemote(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.startRemoteVideoRender({
				account : 'test1',
			   zFront: false
			});
  		}
  		
  		function addComingCallingListener(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.addComingCallingListener({
				enable : true
			},function(ret,err){
				api.alert( {msg:JSON.stringify( ret )});
				chatId = ret.chatId;
			});
  		}
  		
  		
  		var chatId;
  		
  		function accept(){
  			var netEaseAVChat = api.require('netEaseAVChat');
			netEaseAVChat.accept({
				chatId : chatId
			},function(ret,err){
				api.alert( {msg:JSON.stringify( ret )});
				api.alert( {msg:JSON.stringify( err )});
			});
  		}
    
    </script>
    
   <body>
    <div id="wrap">
        <div id="main">
        	<br>
			<div class="clickbtn" tapmode="active" onclick="initAV()" >initAV</div>
			
			<div class="clickbtn" tapmode="active" onclick="login()" >login</div>
			
			<div class="clickbtn" tapmode="active" onclick="enableRtc()" >enableRtc</div>
			
			<div class="clickbtn" tapmode="active" onclick="setParams()" >setParams</div>
			
			<div class="clickbtn" tapmode="active" onclick="addLocalView()" >addLocalView</div>
			
			<div class="clickbtn" tapmode="active" onclick="setVideo()" >setVideo</div>
			
			<div class="clickbtn" tapmode="active" onclick="setPreview()" >setPreview</div>
			
			<div class="clickbtn" tapmode="active" onclick="startLocalVideoRender()" >startLocalVideoRender</div>
			
			<div class="clickbtn" tapmode="active" onclick="call()" >call</div>
			
			<div class="clickbtn" tapmode="active" onclick="setRemoteView()" >setRemoteView</div>
			
			<div class="clickbtn" tapmode="active" onclick="startRemote()" >startRemote</div>
			
			<div class="clickbtn" tapmode="active" onclick="addComingCallingListener()" >addComingCallingListener</div>
			
			<div class="clickbtn" tapmode="active" onclick="accept()" >accept</div>
			
		</div>
	</div>
</body>
    
</html>